<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card class="tree-card">
        <trees-tools :node-data="companyInfo" :is-company="true" @showDialog="showDialogFn" />
        <hr>
        <el-tree :data="depts" :props="{label: 'name'}" default-expand-all>
          <template #default="{data}"> <!-- <template v-slot:default="{data}"> -->
            <!-- <template slot="default" slot-scope="{data}"> -->
            <trees-tools :node-data="data" @showDialog="showDialogFn" /></template>
        </el-tree>
      </el-card>
    </div>
    <addDepts :is-show-dialog.sync="isShowDialog" :node-data="nodeData" @addDepts="addDeptsFn" /></div>
</template>

<script>
import treesTools from './components/trees-tools.vue'
import { getDepartments } from '@/api/departments'
import { listToTreeData } from '@/utils/index'
import addDepts from './components/addDepts.vue'
export default {
  components: { treesTools, addDepts },
  data() {
    return {
      companyInfo: {
        name: '黑马程序员',
        manager: '负责人'
      },
      depts: [
      ],
      isShowDialog: false,
      nodeData: {}
    }
  },
  async created() {
    await this.addDeptsFn()
  },
  methods: {
    showDialogFn(nodeData) {
      this.isShowDialog = true
      this.nodeData = nodeData
    },
    async addDeptsFn() {
      const { depts } = await getDepartments()
      this.depts = depts
      this.depts = listToTreeData(this.depts, '')
    }
  }

}
</script>

<style scoped>
.tree-card {
  padding: 30px  140px;
  font-size:14px;
}
</style>
